package com.quanyue.music.file.service.impl;

import com.quanyue.auto.util.AssertUtils;
import com.quanyue.music.domain.entity.FmSort;
import com.quanyue.music.file.mapper.FMSortMapper;
import com.quanyue.music.file.service.FMSortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class FMSortServiceImpl implements FMSortService {
    @Autowired
    private FMSortMapper fmSortMapper;

    @Override
    public void add(FmSort sort) {
        sort.setCreateTime(LocalDateTime.now());
        sort.setModifyTime(LocalDateTime.now());
        sort.setDelFlag(false);
        fmSortMapper.insert(sort);
    }

    @Override
    public void update(FmSort sort) {
        FmSort checkSort = fmSortMapper.findOne(sort.getId());
        AssertUtils.notNull(checkSort, "没有该分类");
        sort.setModifyTime(LocalDateTime.now());
        sort.setDelFlag(false);
        fmSortMapper.update(sort);
    }

    @Override
    public void delete(String id) {
        FmSort sort = new FmSort();
        sort.setId(id);
        sort.setDelFlag(true);
        sort.setModifyTime(LocalDateTime.now());
        fmSortMapper.updateSelective(sort);
    }

    @Override
    public List<FmSort> findList() {
        return fmSortMapper.findAllValid();
    }
}
